<template>
  <div>
    <div class="logo">
      <img src="static/images/ic_launcher.svg">
      <p>启辕汽车</p>
    </div>
    <item class="y-item">
      <span class="item-title"><i class="ion-android-person" style="font-size: 20px;"></i></span>
      <input type="text" class="y-item-input" name="carTitle" v-model="accountName" placeholder="用户名" required>
    </item>
    <item class="y-item">
      <span class="item-title"><i class="ion-android-lock" style="font-size: 20px;"></i></span>
      <input type="password" class="y-item-input" name="carTitle" v-model="accountPassword" placeholder="密码" required>
    </item>
    <div class="outbtn" style="margin-top:50px"><md-button class="button button-assertive button-block" @click.native="login()">登录</md-button></div>
    <div class="addtext">
      <span @click="forget">忘记密码？</span>
      <span @click="cooperation">启辕合作</span>
    </div>
  </div>
    
</template>
<script>
  export default {
    data() {
      return {
        accountName:'',
        accountPassword:'',
        openId:''
      }
    },
    created:function(){
      if (sess.get('userSession')) {
        this.accountName = sess.get('userSession').accountName;
      }
      this.openId = sess.get('wxOpenId');
    },
    methods: {
      forget () {
        this.$router.push({
							path: '/retrieve'
				})
      },
      cooperation () {
        this.$router.push({
							path: '/cooperation'
				})
      },
      login(){
        if (this.accountName == '' || this.accountPassword == '') {
          
          $toast.show('请输入用户名密码',2000);
        }
        else{
          axios.get(baseUrl+'/controller/Login',{params:{
              accountName:this.accountName,
              accountPassword:this.accountPassword,
              wxOpenId:this.openId,
              applicationId:171220110147618,
              loginUrl:'/controller/LoginJson',
              logoutUrl:'/controller/LoginJson',
              exceptionUrl:'/controller/LoginJson'
            }
          })
          .then(function(res){
            sess.set('userSession',res.data.result);
            $router.forward(res.data.result.resourceList[0].resourceUrl);
          })
        }
      },
      GetQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(  ).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
      }
    },
  }
</script>
<style scope>
    .logo{
      text-align: center;
      padding: 50px 0;
      background-color: #fff;
    }
    .login-small{margin: 3px 15px;}
    .login-small-left{float: left;}
    .login-small-right{ float: right;}
</style>